package com.car.util;

import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;


/**
 * 常量
 * @author yuxiaojiang
 *
 */

public class Const {
	
	public  final static String resultState= "SUCCESS";
	public  final static String endcoding= "utf-8";
	

	/**
	 * 用户的默认密码
	 */
	public static String DEFAULD_PWD = "123456";
	
	/**
	 * 前台 用于保存session
	 */
 
	public static String SESSION_USER = "school";
	/**
	 * 上传图片的服务器目录
	 */

	public static String uploadImageDire = "uploadoa/images";

	
	/**
	 * 上传视频的服务器目录
	 */

	public static String uploadVideoDire = "uploadoa/video";
	
	
	/**
	 * 上传文件的服务器目录
	 */

	public static String uploadWordDire = "uploadoa/doc";
	
	
	
	
	/**
	 * 项目运行的环境
	 */
	public static Boolean runInProduct = true; 
	//public static Boolean runInProduct = false;
	
  

	/**
	 * 男
	 */
	public static String sexMan = "0";
	/**
	 * 女
	 */
	public static String sexWoman = "1";
	
	/**
	 * 状态Y
	 */
	public static String state_yes = "Y";
	
	/**
	 * 状态N
	 */
	public static String state_no = "N";
 
	
 

	/**
	 * 不判断Session的URI的正则表达式
	 */
	//private static final String UNCHECKURI_REGEX = ".+/login[/\\.].*|.+/test/.+|.+/public/.+(?<!\\.jsp)$";//".*/login[/\\.].*|.*/test/.*|.*/public/.+(?:[^\\.]...|.[^j]..|..[^s].|...[^p])";
	//private static final String UNCHECKURI_REGEX = ".+/index[/\\.].*|.+/login[/\\.].*|.+/front/.+(?<!\\.ftl)$";//".*/login[/\\.].*|.*/test/.*|.*/public/.+(?:[^\\.]...|.[^j]..|..[^s].|...[^p])";
	private static final String UNCHECKURI_REGEX = ".+/login[/\\.].*|.+/netCouserExam/.+(?<!\\.ftl)$";//".*/login[/\\.].*|.*/test/.*|.*/public/.+(?:[^\\.]...|.[^j]..|..[^s].|...[^p])";
	/**
	 * 不检查的匹配 表达式
	 */
	private static final Pattern UNCHECKURI_PATTERN = Pattern.compile(UNCHECKURI_REGEX);
	/**
	 * 判断Session的URI的正则表达式
	 */
	private static final String CHECKURI_REGEX = ".+\\.ftl|.+\\.htm|/netCourse/$";//".+\\.jsp$|.+\\.do$|.+/auth/.+(?:[^\\.]..|.[^j].|..[^s])";
	/**
	 * 获取图片上传目录
	 * @param request
	 * @param iconDirectory 上传图片的目录
	 * @param runInProduct 是否运行在生产
	 * @return
	 */
	public static String getUploadFilePath(HttpServletRequest request, String iconDirectory,Boolean runInProduct){
		
		if(runInProduct!=null&&runInProduct){//运行在生产环境
			return request.getSession().getServletContext().getRealPath("/").replace("netCourse", "") + iconDirectory + "/";
//			return "upload"+"/"+ iconDirectory + "/";
			
		}else{
			return "D:/WorkSpace/netCourse/WebContent/"+iconDirectory+"/";
			//return "D:/work/workspaceMyhous/school3D/WebContent/"+iconDirectory+"/";
		}
	}
	/**
	 * 获取图片的url
	 * @param request
	 * @param iconDb
	 * @param iconDirectory
	 * @return
	 */
	public static String getPrefixUrl(HttpServletRequest request, String iconDb, String iconDirectory){
	    String imageUrl = "";
	    if (!StringUtils.isEmpty(iconDb)) {
	      imageUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/" + iconDirectory + "/" + iconDb;
	    }
	    return imageUrl;
	 }
	
	/**
	 * 匹配的表达式
	 */
	private static final Pattern CHECKURI_PATTERN = Pattern.compile(CHECKURI_REGEX);
	
	
	public static void main(String[] args) {
		String url = "http://localhost:8080/platform/";
		System.out.println(Const.getCheckUriPattern().matcher(url).matches());
	}
	/**
	 * 不判断Session的URI的正则表达式
	 * 
	 * @return the uNCHECKURI_PATTERN
	 */
	public static Pattern getUnCheckUriPattern() {
		return UNCHECKURI_PATTERN;
	}

	/**
	 * 判断Session的URI的正则表达式
	 * 
	 * @return the cHECKURI_PATTERN
	 */
	public static Pattern getCheckUriPattern() {
		return CHECKURI_PATTERN;
	}
}
